#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int N = 2e5 + 10;
#define INF 0x3f3f3f3f;
typedef long long int ll;
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//----------------------------------------------------------------------------//
ll a, b; //从q开始 a b a b a b 为当天买一个土豆的价格
ll n, m; //n要买多少个,第一天买m个送1个
void solve()
{
    cin >> a >> b;
    cin >> n >> m;

    if(m >= n) cout << min(a, b)*n << '\n';
    else
    {
        cout << min(n * b, (n / (m + 1))*a * m + (n - (n / (m + 1)) * (m + 1))*min(a, b)) << '\n';
    }


}

int main()
{
    close();
    int T;
    cin >> T;
    while (T--) solve();
    return 0;
}